package jalus.dao;

import jalus.model.BlogLink;
import jalus.model.PMF;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class BlogLinkDAO {

	public void deleteById(Long id) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		BlogLink blogLink = pm.getObjectById(BlogLink.class, id);
		try{
			pm.deletePersistent(blogLink);
		}finally{
			pm.close();
		}
	}

	public void add(BlogLink blogLink) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			pm.makePersistent(blogLink);
		}finally{
			pm.close();
		}
	}

	@SuppressWarnings("unchecked")
	public List<BlogLink> getALL() {
		PersistenceManager pm = PMF.get().getPersistenceManager();
	    Query query = pm.newQuery(BlogLink.class);
	    pm.setDetachAllOnCommit(true);
	    List<BlogLink> blogLinkList;
	    try{
	    	blogLinkList = (List<BlogLink>) query.execute();
	    }finally{
	    	query.closeAll();
	    }
	    return blogLinkList;
	}

}
